package demo14_ForkJoin;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;
import java.util.stream.LongStream;

/**
 * @author kunkun
 * @className Test03_Stream
 * @Description 使用并行流计算
 * @date 2025/3/6 22:19
 */
public class Test03_Stream {


    public static void main(String[] args) {

        Long startTime = System.currentTimeMillis();

        //rangeClosed：范围，左右闭区间
        //parallel：并行计算
        //Long::sum：函数式接口，加法
        long sum = LongStream.rangeClosed(0L, 10_0000_0000L).parallel().reduce(0, Long::sum);

        Long endTime = System.currentTimeMillis();
        System.out.println("sum="+sum); //500000000500000000
        System.out.println("expend time:"+(endTime-startTime)+"ms");    //126ms

    }



}
